package com.example.feign.controller;

import com.example.feign.entity.Skill;
import com.example.feign.feign.SkillFeign;
import com.example.feign.util.EntityToMap;
import com.example.feign.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/skill")
public class SkillFeignController {

    @Autowired
    SkillFeign skillFeign;

    @GetMapping("/get")
    public Response getSkill(
            @RequestParam(value = "page",required = false) Integer page,
            @RequestParam(value = "size",required = false) Integer size,
            Skill skill){
        Map map = new HashMap<>();
        map = EntityToMap.object2Map(skill);
        return skillFeign.getSkill(page, size, map);
    }

    @GetMapping("/getAll")
    public Response getAllSkill(){
        return skillFeign.getAllSkill();
    }

    @PostMapping("/add")
    public Response addSkill(Skill skill){
        return skillFeign.addSkill(skill);
    }

    @PutMapping("/update")
    public Response updateSkill(Skill skill){
        return skillFeign.updateSkill(skill);
    }

    @PutMapping("/del")
    public Response delSkill(@RequestParam(value = "skillId",required = true) String skillId){
        return skillFeign.delSkill(skillId);
    }

}
